<?php
/**************************
 * Created on Jan 22, 2011
 * By: Jos Pape
 * info: jospape@hotmail.com
 */
include_once "common.php";


function openSubmenu($menuID)
{
	global $_MySQL;
	global $hroot;
	$query = "SELECT * FROM SystemMenu WHERE MenuID = '".str_replace("'","",$menuID)."'";
	$result = $_MySQL->runQuery($query);
	if(mysql_num_rows($result) >= 1)
	{
		?>
		<ul>
		<?php
		while($row =  mysql_fetch_assoc($result))
		{
			?>
			<li>
				<a href="<?=getPageURL($row['PageID']);?>"><?=$row['Name'];?></a>
				<?php
				openSubmenu($row['ID']);
				?>
			</li>
			<?php
		}	
		?>
		</ul>
		<?php
	}
}


function getPageURL($pageID)
{
	global $_MySQL;
	global $hroot;
	$retVal = '#';
	if(!empty($pageID) && is_numeric($pageID))
	{
		// get page
		$query = "SELECT Path FROM SystemPage WHERE ID = '".$pageID."' LIMIT 1";
		$result = $_MySQL->runQuery($query);
		if(mysql_num_rows($result) >= 1)
		{
			$row = mysql_fetch_assoc($result);
			$retVal = $hroot.$row['Path'];
		}
	}
	return $retVal;
}

?>

<html> 
<head> 
	<title>Prijsgezocht DATABASE</title> 
	<link href="<?=$hroot;?>/css/jqModal.css" rel="stylesheet" type="text/css" />
	<link href="<?=$hroot;?>/css/jquery.css" rel="stylesheet" type="text/css" />
	<link href="<?=$hroot;?>/css/style.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="<?=$hroot;?>/javascript/jquery.js" charset="iso-8859-1"></script> 
	<script type="text/javascript" src="<?=$hroot;?>/javascript/jquery-ui.js" charset="iso-8859-1"></script> 
	<script type="text/javascript" src="<?=$hroot;?>/javascript/jquery.metadata.js" charset="iso-8859-1"></script>
	<script type="text/javascript" src="<?=$hroot;?>/javascript/jquery.dropmenu.js" charset="iso-8859-1"></script>
	<script type="text/javascript" src="<?=$hroot;?>/javascript/xml.js" charset="iso-8859-1"></script>
	<script type="text/javascript"> 
		$(document).ready(function() 
		{
			// Submenu
			$('#uitklapMenu').dropmenu({
				effect	: 'fade',
				speed	: "normal",  
				nbsp	: true
			});
			
			// popup
			$('.openPopup').click(function ()
			{
				var url=$(this).attr('href');
				var winTitle=$(this).attr('title');
				var winWidth=$(this).attr('width');
				var winHeight=$(this).attr('height');
				//alert(popupPositieLeft);
				$(".popup").dialog('destroy');
				$(".popup").dialog({
					zIndex: 1,
					title: winTitle,
					draggable: true,
					width: winWidth,
					height: winHeight,
					position: ['center', 40],
					modal: true,
					autoOpen: false,
					close: function(event, ui) { 
						$(".ui-dropdownchecklist-dropcontainer-wrapper").each(function(){
							$(this).css('display','none');
						});
					},
					open: function(event, ui) {
						//display correct dialog content
						$(".popup").load(url);
					}
				});
				$(".popup").dialog("open");
				return false;
			});
	    });
	</script> 
</head>
<body style="width:100%; height:100%; overflow:hidden;">
<?php
// logged in ?!?!?
if(!isset($_SESSION['login']['ID']) || empty($_SESSION['login']['ID']) || !is_numeric($_SESSION['login']['ID']))
{
	// login form....
	include_once $root."/login.php";
	include_once $root."/footer.php";
	exit;
}
else
{
	?>
	<div class="popup"></div>
		<!-- Start the layout! --> 
		<div id="menu">
			<ul id="uitklapMenu">
				<?php
				$query = "SELECT * FROM SystemMenu WHERE MenuID IS NULL";
				$result = $_MySQL->runQuery($query);
				while($row = mysql_fetch_assoc($result))
				{
					?>
					<li>
						<a href="<?=getPageURL($row['PageID']);?>"><?=$row['Name'];?></a>
						<?php
						openSubmenu($row['ID']);
						?>
					</li>
					<?php
				}
				?>
			</ul>
		</div>
		<div id="page">
	<?php
}